package servlet;
/*
    date：
    topic：
    
*/

import entity.Companyinfo;
import entity.pageBean;
import service.CompanyinfoDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/page")
public class page extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public static CompanyinfoDao companyinfoDao =  new CompanyinfoDao();
    String sql;
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        pageBean pBean = (pageBean)session.getAttribute("page");
        if(pBean==null) {
            sql = "select count(*) from rz ";
            int count =companyinfoDao.getCount(sql);
            //设置页数
            pBean  = new pageBean(3, count, 1);
        }else {
            String cString = request.getParameter("currentPage");
            if(cString==null)cString="1";
            int currentPage = Integer.parseInt(cString);
            pBean.setCurrentPage(currentPage);
        }
        String sql = "select ip,rname, rtime from rz limit "+pBean.getBeginIndex()+","+pBean.getEveryPage();
        List<Companyinfo> list = companyinfoDao.getList(sql);
        session.setAttribute("page", pBean);
        request.setAttribute("list", list);
        request.getRequestDispatcher("DateView.jsp").forward(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}

